define(function(require, exports, module) {
	'use strict';
    
    var rk = require('rk');
    require('../../su/xsySuRefer/widget');

    $.widget('rk.xsyApprovalRefer', $.rk.xsySuRefer, {
        options: {
            iconClass: 'xsy_su_refer_approval_icon',
        },
        _create: function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;

            me._super();

            var config = {
                iconClass: opt.iconClass,
                children: [
                    {   
                        type: 'card'
                    }
                ],
                showEntityMenu : false,
                linkOfMore : '/approval_list.action?fromBelongId=' + opt.parentEntityId + '&fromDataId=' + me._getDetailId(),
                linkOfFinal: '/final/approval.action?id={{id}}',
                childrenConfig:{
                    showMenu : false 
                },
                itemRender: {
                    'status': function(rowData, cellData, itemType){
                        console.log(rowData);
                        var approvalUsers = rowData.users;
                        var userHtml = approvalUsers.map(function(item, i){
                            return "<a class='username' href='/final/user.action?uid=" + item.value + "' ucard='uid=" + item.value + "'>" + item.label + "</a>";
                            
                        }).join(' ');
                        var status = rowData.status;
                        var cancelFlg = rowData.cancelFlg;

                        var applyType = rowData.applyType == 0 ? ' 审批' : ' 会签';

                        if(status == 1){
                            userHtml = "等待 " + userHtml + applyType;
                        }else if(status == 2 && cancelFlg == 0){
                            userHtml = "被 " + userHtml + " 拒绝";
                        }else if(cancelFlg == 1){
                            userHtml = '已撤回';
                        }else if(status == 3){
                            userHtml = "审批通过"
                        }

                        return userHtml;
                    }
                }
            };

            var data = {belongId:me._getCommonData().belongId}
            me._loadData(data, function(result){
                /*if(me.data_bound){
                    me.bindData(result.self);
                }else{
                    me._render(config, result);
                }*/
                 me._render(config, result);
            })
        }
    });
});